package se19team1e.gui.awt;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import se19team1e.controller.Application;
import se19team1e.controller.ViewJobResponseDetailController;
import se19team1e.entity.JobResponseDTO;
import se19team1e.gui.BaseScreen;
import se19team1e.gui.JobAdvertResponseDetailScreen;
import se19team1e.util.DateUtils;


/**
* @author Tay Toh Tong
*/
public class AWTJobAdvertResponseDetailScreen extends AWTBaseScreen implements
		JobAdvertResponseDetailScreen {
			private JPanel mainPanel;
			private JPanel titlePanel;
			private JLabel JobResponseTextLabel;
			private JPanel summaryPanel;
			private JLabel dateTextLabel;
			private JButton backButton;
			private JTextArea resumeTextArea;
			private JLabel dateLabel;
			private JLabel titleTextLabel;
			private JLabel titleLabel;
			private JPanel resumePanel;
			
			private ViewJobResponseDetailController controller;
			private Application application;
			private BaseScreen previousScreen;
			
			public AWTJobAdvertResponseDetailScreen(Application application, BaseScreen previousScreen) {
				super(application);
				this.application = application;
				this.previousScreen = previousScreen;

				mainPanel = new JPanel();
				BorderLayout MainPanelLayout = new BorderLayout();
				MainPanelLayout.setHgap(10);
				MainPanelLayout.setVgap(10);
				getContentPane().add(mainPanel);
				mainPanel.setLayout(MainPanelLayout);
				mainPanel.setBounds(0, 0, 484, 564);
				mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				{
					titlePanel = new JPanel();
					BorderLayout resumePanelLayout = new BorderLayout();
					resumePanelLayout.setHgap(10);
					resumePanelLayout.setVgap(10);
					mainPanel.add(titlePanel, BorderLayout.NORTH);
					BorderLayout titlePanelLayout = new BorderLayout();
					titlePanel.setLayout(titlePanelLayout);
					titlePanel.setPreferredSize(new java.awt.Dimension(484, 26));
					{
						JobResponseTextLabel = new JLabel();
						titlePanel.add(JobResponseTextLabel, BorderLayout.CENTER);
						JobResponseTextLabel.setText("Job Reponse");
						JobResponseTextLabel.setLayout(null);
					}
					{
						backButton = new JButton();
						BorderLayout backButtonLayout = new BorderLayout();
						titlePanel.add(backButton, BorderLayout.EAST);
						backButton.setLayout(null);
						backButton.setText("Back");
						backButton.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								backButtonActionPerformed(evt);
							}
						});
					}
				}
				{
					summaryPanel = new JPanel();
					mainPanel.add(summaryPanel, BorderLayout.CENTER);
					GridBagLayout summaryPanelLayout = new GridBagLayout();
					summaryPanelLayout.rowWeights = new double[] {0.1, 0.1};
					summaryPanelLayout.rowHeights = new int[] {7, 7};
					summaryPanelLayout.columnWeights = new double[] {0.0, 0.1};
					summaryPanelLayout.columnWidths = new int[] {104, 7};
					summaryPanel.setLayout(summaryPanelLayout);
					summaryPanel.setPreferredSize(new java.awt.Dimension(484, 73));
					summaryPanel.setSize(484, 100);
					{
						dateTextLabel = new JLabel();
						BorderLayout dateLabelLayout = new BorderLayout();
						dateLabelLayout.setHgap(10);
						summaryPanel.add(dateTextLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						dateTextLabel.setText("Date: ");
						dateTextLabel.setLayout(null);
					}
					{
						titleTextLabel = new JLabel();
						summaryPanel.add(titleTextLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						titleTextLabel.setText("Title");
						titleTextLabel.setLayout(null);
					}
					{
						dateLabel = new JLabel();
						summaryPanel.add(dateLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 10, 0));
						dateLabel.setText("Actual Date");
						dateLabel.setLayout(null);
					}
					{
						titleLabel = new JLabel();
						BorderLayout jLabel1Layout = new BorderLayout();
						jLabel1Layout.setHgap(10);
						summaryPanel.add(titleLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						titleLabel.setText("Actual Title");
						titleLabel.setLayout(null);
					}

				}
				{
					resumePanel = new JPanel();
					mainPanel.add(resumePanel,BorderLayout.SOUTH);
					FlowLayout resumePanelLayout = new FlowLayout();
					resumePanelLayout.setAlignment(FlowLayout.LEFT);
					resumePanel.setLayout(resumePanelLayout);
					resumePanel.setPreferredSize(new java.awt.Dimension(484, 458));
					resumePanel.setSize(484, 500);
					{
						resumeTextArea = new JTextArea();
						resumeTextArea.setEditable(false);
						resumePanel.add(resumeTextArea);
						resumeTextArea.setText("Resume Text");
						resumeTextArea.setPreferredSize(new java.awt.Dimension(474, 450));
					}
				}

				{
					this.setSize(500, 600);
				}
			}

	@Override
	public void initialize(ViewJobResponseDetailController controller, JobResponseDTO jobResponse) {
		this.controller = controller;
		this.clearFields();
		this.fillFields(jobResponse);

	}

	@Override
	public void updateAvailableActions() {
		// TODO Auto-generated method stub

	}
	
	public void clearFields(){
		this.dateLabel.setText("");
		this.titleLabel.setText("");
		this.resumeTextArea.setText("");
	}
	
	public void fillFields(JobResponseDTO jobResponse){
		this.dateLabel.setText(DateUtils.getStringFromDate(jobResponse.getDate(),"dd-MMM-yyyy"));
		this.titleLabel.setText(jobResponse.getTitle());
		this.resumeTextArea.setText(jobResponse.getResume());
	}
	
	private void backButtonActionPerformed(ActionEvent evt) {
		System.out.println("backButton.actionPerformed, event="+evt);
		//TODO add your code for backButton.actionPerformed
		this.controller.backToPreviousScreen();
	}

}
